//
//  WeatherInfoVC.m
//  Cunli
//
//  Created by lilubin on 15/7/15.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "WeatherInfoVC.h"
#import "UIImageView+WebCache.h"
#import "NSString+MD5.h"
#import "UINavigationController+FDFullscreenPopGesture.h"

@interface WeatherInfoVC ()
{
    
}
@end

@implementation WeatherInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setAllUIKits];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)setAllUIKits
{
    self.fd_prefersNavigationBarHidden = YES;
//    self.navigationController.navigationBar.hidden = YES;
    NSMutableArray *resultsArray = [NSMutableArray array];
    resultsArray = _weatherDic[@"results"];
    NSMutableDictionary *weatherResults = [NSMutableDictionary dictionary];
    weatherResults = resultsArray[0];
    NSString *currentCity = [weatherResults objectForKey:@"currentCity"];
//    self.title = currentCity;
    _cityLabel.text = currentCity;
    _pm2p5label.text = [NSString stringWithFormat:@"PM2.5  %@", weatherResults[@"pm25"]];
    NSArray *weatherDataArray = weatherResults[@"weather_data"];
    NSArray *dayImgArray = @[_day0ImgView, _day1ImgView, _day2ImgView, _day3ImgView];
    NSArray *nightImgArray = @[_night0ImgView, _night1ImgView, _night2ImgView, _night3ImgView];
    NSArray *dateLabelArray = @[_data0label, _date1label, _date2label, _date3label];
    NSArray *teperatureArray = @[_temperature0label, _temperature1label, _temperature2label, _temperature3label];
    NSArray *windArray = @[_wind0label, _wind1label, _wind2label, _wind3label];
    
    _day0ImgView.layer.cornerRadius = 10;
    _day0ImgView.layer.masksToBounds = YES;
    
    _night0ImgView.layer.cornerRadius = 10;
    _night0ImgView.layer.masksToBounds = YES;

    _day1ImgView.layer.cornerRadius = 6;
    _day1ImgView.layer.masksToBounds = YES;
    
    _day2ImgView.layer.cornerRadius = 6;
    _day2ImgView.layer.masksToBounds = YES;
    
    _day3ImgView.layer.cornerRadius = 6;
    _day3ImgView.layer.masksToBounds = YES;
    
    _night1ImgView.layer.cornerRadius = 6;
    _night1ImgView.layer.masksToBounds = YES;

    _night2ImgView.layer.cornerRadius = 6;
    _night2ImgView.layer.masksToBounds = YES;

    _night3ImgView.layer.cornerRadius = 6;
    _night3ImgView.layer.masksToBounds = YES;


    
    for (int i = 0; i<4; i++) {
        NSDictionary *dic = weatherDataArray[i];
        [dateLabelArray[i] setText:dic[@"date"]];
        [teperatureArray[i] setText:dic[@"temperature"]];
        [windArray[i] setText:[NSString stringWithFormat:@"%@%@", dic[@"weather"], dic[@"wind"]]];
        [dayImgArray[i] setImageWithURL:[NSURL URLWithString:dic[@"dayPictureUrl"]]];
        [nightImgArray[i] setImageWithURL:[NSURL URLWithString:dic[@"nightPictureUrl"]]];
    }
    NSString *weatherStr = weatherDataArray[0][@"weather"];
    if ([NSString theMaxString:weatherStr containSpecificCharacter:@"晴"])
    {
        [weatherBgImgView setImage:[UIImage imageNamed:@"sunny"]];
    }
    else if([NSString theMaxString:weatherStr containSpecificCharacter:@"阴"])
    {
        [weatherBgImgView setImage:[UIImage imageNamed:@"yin"]];
    }
    else if([NSString theMaxString:weatherStr containSpecificCharacter:@"雨"])
    {
        [weatherBgImgView setImage:[UIImage imageNamed:@"rain"]];
    }
    else if([NSString theMaxString:weatherStr containSpecificCharacter:@"雪"])
    {
        [weatherBgImgView setImage:[UIImage imageNamed:@"snow"]];
    }else if([NSString theMaxString:weatherStr containSpecificCharacter:@"云"])
    {
        [weatherBgImgView setImage:[UIImage imageNamed:@"cloud"]];
    }
    
}


- (IBAction)backAction:(id)sender {
    if (self.navigationController != nil) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

@end
